package com.dynaBlaster.view;

import com.dynaBlaster.core.Direction;
import com.dynaBlaster.core.Point;
import com.dynaBlaster.game.GameConfig;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;



public class BaseView {
	
	public GameView view;
	Bitmap[] bitmapNSEW;

	
	public BaseView(GameView view){
		this.view = view;
	}
	
	
	/**
	 * loads and returns a bitmap with drawble
	 */
	Bitmap loadImg(Drawable drawable) {

		int img_size = GameConfig.TILE_SIZE;
		
		Bitmap bitmap = Bitmap.createBitmap(img_size, img_size, Bitmap.Config.ARGB_8888);
		Canvas canvasBmp = new Canvas(bitmap);
		drawable.setBounds(0, 0, img_size, img_size);
		drawable.draw(canvasBmp);

		return bitmap;
	}
	
	
	/**
	 * Set 4 images for the creature each representing it looking in different
	 * direction
	 * 
	 * @param imgs
	 *            : [NORTH, SOUTH, EAST, WEST ]
	 */
	void loadImg(Drawable[] nsew) {
		int img_size = GameConfig.TILE_SIZE;

		bitmapNSEW = new Bitmap[4];
		for (int i = 0; i < 4; i++) {
			Drawable db = nsew[i];
			Bitmap bitmap = Bitmap.createBitmap(img_size, img_size, Bitmap.Config.ARGB_8888);
			Canvas canvasBmp = new Canvas(bitmap);
			db.setBounds(0, 0, img_size, img_size);
			db.draw(canvasBmp);

			bitmapNSEW[i] = bitmap;
		}
	}
	

	public void draw(Canvas canvas, Point pos, Direction dir) {
		int size = (GameConfig.TILE_SIZE - 1) / 2;
		
		canvas.drawBitmap(bitmapNSEW[dir.ordinal()], pos.x - size, pos.y - size, new Paint());
		/*
		 * Paint p = new Paint(); canvas.drawCircle(pos.x-size, pos.y-size, 2,
		 * new Paint()); canvas.drawCircle(pos.x, pos.y, 4, new Paint());
		 * 
		 * int startX=pos.x , startY=pos.y, stopX=startX, stopY=startY; switch
		 * (dir){ case NORTH: stopY-=speed*3; canvas.drawLine(startX, startY,
		 * stopX, stopY, new Paint()); canvas.drawCircle(stopX, stopY,3, new
		 * Paint()); break; case SOUTH: stopY+=speed*3; canvas.drawLine(startX,
		 * startY, stopX, stopY, new Paint()); canvas.drawCircle(stopX, stopY,3,
		 * new Paint()); break; case EAST: stopX+=speed*3;
		 * canvas.drawLine(startX, startY, stopX, stopY, new Paint());
		 * canvas.drawCircle(stopX, stopY,3, new Paint()); break; case WEST:
		 * stopX-=speed*3; canvas.drawLine(startX, startY, stopX, stopY, new
		 * Paint()); canvas.drawCircle(stopX, stopY,3, new Paint()); break; }
		 * canvas.drawCircle(pos.x, pos.y, 4, new Paint());
		 */
	}


}
